package com.cdut.logistics.model.dao.system;

import com.cdut.logistics.model.entity.system.User;
/**
 * 
 * @ClassName: userDAO  
 * @Description: TODO(用户类的DAO，用于与数据库交互)  
 * @author lxh
 * @date 2018年1月28日 下午2:40:35
 */
public class userDAO {
	User user=new User();
	/**
	 * 
	 * @Title: DeleteUser  
	 * @Description: TODO(逻辑删除用户)
	 * @author lxh
	 * @param userid
	 * @return
	 * @throws
	 */
	public boolean DeleteUser(String id){
		try{
		user=user.findById(id);
		user.set("active",0);
		}catch(Exception e){}
		boolean result=user.update();
		return result;
	}
	/**
	 * 
	 * @Title: queryUserInfo  
	 * @Description: TODO(查询用户信息)
	 * @author lxh
	 * @param userid
	 * @return
	 * @throws
	 */
	public User queryUserInfo(String id){
		try{
			user=user.findById(id);
		}catch(Exception e){
			
		}
		return user;
	}
	/**
	 * 
	 * @Title: UpdateUserInfo  
	 * @Description: TODO(修改用户信息)
	 * @author lxh
	 * @param username
	 * @param identity
	 * @param password
	 * @param userid
	 * @param student_id
	 * @param school_id
	 * @param academy_id
	 * @param dorm_id
	 * @param major_id
	 * @param sex
	 * @param role_id
	 * @param rep_id
	 * @return
	 * @throws
	 */
	public boolean UpdateUserInfo(String username,String password,String identity, String student_id, String school_id, String academy_id,
			String dorm_id, String major_id, String sex, String role_id,String rep_id,String id){
		try{
		user=user.findById(id);
		user.set("username",username);
		user.set("password",password);
		user.set("student_id",student_id);
		user.set("school_id", school_id);
		user.set("academy_id",academy_id);
		user.set("dorm_id",dorm_id);
		user.set("major_id",major_id);
		user.set("sex",sex);
		user.set("role_id",role_id);
		user.set("rep_id",rep_id);
		user.set("identity",identity);
		}catch(Exception e){
			
		}
		boolean result=user.update();
		return result;
	}
	/**
	 * 
	 * @Title: AddUser  
	 * @Description: TODO(新增用户)
	 * @author lxh
	 * @param username
	 * @param identity
	 * @param password
	 * @param student_id
	 * @param school_id
	 * @param academy_id
	 * @param dorm_id
	 * @param major_id
	 * @param sex
	 * @param role_id
	 * @param rep_id
	 * @return
	 * @throws
	 */
	public boolean AddUser(String username,String password,String identity, String student_id, String school_id, String academy_id,
			String dorm_id, String major_id, String sex, String role_id, String rep_id,String is_use,String active) {
		try{
		user.set("username",username);
		user.set("password",password);
		user.set("student_id",student_id);
		user.set("school_id", school_id);
		user.set("academy_id",academy_id);
		user.set("dorm_id",dorm_id);
		user.set("major_id",major_id);
		user.set("sex",sex);
		user.set("role_id",role_id);
		user.set("rep_id",rep_id);
		user.set("identity",identity);
		user.set("is_use", is_use);
		user.set("active",active);
		}catch(Exception e){}
		boolean result = user.save();
		return result;
	}
	
}
